package com.manage.project.biz.controller;

import java.util.List;

import com.manage.project.biz.domain.BizGonglu;
import com.manage.project.biz.service.IBizGongluService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.project.biz.domain.BizSuidao;
import com.manage.project.biz.service.IBizSuidaoService;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.framework.web.page.TableDataInfo;

/**
 * 隧道信息Controller
 *
 * @author liutao

 */
@RestController
@RequestMapping("/biz/suidao")
public class BizSuidaoController extends BaseController
{
    @Autowired
    private IBizSuidaoService bizSuidaoService;
    @Autowired
    private IBizGongluService bizGongluService;

    /**
     * 查询隧道信息列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:suidao:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizSuidao bizSuidao)
    {
        startPage();
        List<BizSuidao> list = bizSuidaoService.selectBizSuidaoList(bizSuidao);
        for (BizSuidao suidao : list) {
            BizGonglu bizGonglu = bizGongluService.selectBizGongluById(Long.valueOf(suidao.getField19()));
            if(bizGonglu!=null){
                suidao.setField22(bizGonglu.getField2());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出隧道信息列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:suidao:export')")
    @Log(title = "隧道信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizSuidao bizSuidao)
    {
        List<BizSuidao> list = bizSuidaoService.selectBizSuidaoList(bizSuidao);
        ExcelUtil<BizSuidao> util = new ExcelUtil<BizSuidao>(BizSuidao.class);
        return util.exportExcel(list, "隧道信息数据");
    }

    /**
     * 获取隧道信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:suidao:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizSuidaoService.selectBizSuidaoById(id));
    }

    /**
     * 新增隧道信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:suidao:add')")
    @Log(title = "隧道信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizSuidao bizSuidao)
    {

        return toAjax(bizSuidaoService.insertBizSuidao(bizSuidao));
    }

    /**
     * 修改隧道信息
     */
    @Log(title = "隧道信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizSuidao bizSuidao)
    {
        return toAjax(bizSuidaoService.updateBizSuidao(bizSuidao));
    }

    /**
     * 删除隧道信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:suidao:remove')")
    @Log(title = "隧道信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizSuidaoService.deleteBizSuidaoByIds(ids));
    }
}
